<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>pthread_cond_init</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_1243">&nbsp;</a>NAME</h4><blockquote>
pthread_cond_init, pthread_cond_destroy - initialise and destroy
condition variables
</blockquote><h4><a name = "tag_000_007_1244">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="pthread.h.html">pthread.h</a>&gt;

int pthread_cond_init(pthread_cond_t *<i>cond</i>,
    const pthread_condattr_t *<i>attr</i>);
int pthread_cond_destroy(pthread_cond_t *<i>cond</i>);
pthread_cond_t <i>cond</i> = PTHREAD_COND_INITIALIZER;
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_1245">&nbsp;</a>DESCRIPTION</h4><blockquote>
The function
<i>pthread_cond_init()</i>
initialises the condition variable referenced by
<i>cond</i>
with attributes referenced by
<i>attr</i>.
If
<i>attr</i>
is NULL,
the default condition variable attributes are used;
the effect is the same as passing the address
of a default condition variable attributes object.
Upon successful initialisation,
the state of the condition variable becomes initialised.
<p>
Attempting to initialise an already initialised
condition variable
results in undefined behaviour.
<p>
The function
<i>pthread_cond_destroy()</i>
destroys the given condition variable specified by
<i>cond</i>;
the object becomes, in effect, uninitialised.
An implementation may cause
<i>pthread_cond_destroy()</i>
to set the object referenced by
<i>cond</i>
to an invalid value.
A destroyed condition variable object
can be re-initialised using
<i>pthread_cond_init()</i>;
the results of otherwise referencing the object after it has been destroyed
are undefined.
<p>
It is safe to destroy an initialised condition variable
upon which no threads are currently blocked.
Attempting to destroy a condition variable
upon which other threads are currently blocked
results in undefined behaviour.
<p>
In cases where default condition variable attributes are appropriate,
the macro PTHREAD_COND_INITIALIZER
can be used to initialise condition variables that are statically allocated.
The effect is equivalent to dynamic initialisation by a call to
<i>pthread_cond_init()</i>
with parameter
<i>attr</i>
specified as NULL, except that no error checks are performed.
</blockquote><h4><a name = "tag_000_007_1246">&nbsp;</a>RETURN VALUE</h4><blockquote>
If successful, the
<i>pthread_cond_init()</i>
and
<i>pthread_cond_destroy()</i>
functions return zero.
Otherwise, an error number is returned to indicate the error.
The [EBUSY] and [EINVAL]
error checks, if implemented,
act as if they were performed immediately
at the beginning of processing for the function
and caused an error return
prior to modifying the state of the condition variable specified by
<i>cond</i>.
</blockquote><h4><a name = "tag_000_007_1247">&nbsp;</a>ERRORS</h4><blockquote>
The 
<i>pthread_cond_init()</i>
function will fail if:
<dl compact>

<dt>[EAGAIN]<dd>
The system lacked the necessary resources (other
than memory) to initialise another condition variable.

<dt>[ENOMEM]<dd>
Insufficient memory exists to initialise the condition variable.

</dl>
<p>
The
<i>pthread_cond_init()</i>
function may fail if:
<dl compact>

<dt>[EBUSY]<dd>
The implementation has detected an attempt
to re-initialise the object referenced by
<i>cond</i>,
a previously initialised, but
not yet destroyed, condition variable.

<dt>[EINVAL]<dd>
The value specified by
<i>attr</i>
is invalid.

</dl>
<br>
<p>
The
<i>pthread_cond_destroy()</i>
function may fail if:
<dl compact>

<dt>[EBUSY]<dd>
The implementation has detected an attempt to destroy
the object referenced by
<i>cond</i>
while it is referenced
(for example, while being used in a
<i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i>
or
<i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i>)
by another thread.

<dt>[EINVAL]<dd>
The value specified by
<i>cond</i>
is invalid.

</dl>
<p>
These functions will not return an error code of [EINTR].
</blockquote><h4><a name = "tag_000_007_1248">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1249">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1250">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1251">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="pthread_cond_signal.html">pthread_cond_signal()</a></i>,
<i><a href="pthread_cond_broadcast.html">pthread_cond_broadcast()</a></i>,
<i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i>,
<i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i>,
<i><a href="pthread.h.html">&lt;pthread.h&gt;</a></i>.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the POSIX Threads Extension (1003.1c-1995)
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

